package cn.edu.scau.cmi.dengzejun.chapter11;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.*;
import java.util.*;

public class PoliceListenForSeven implements ItemListener{
	JComboBox choice;
	JTextArea textShow;
	public void setJComboBox(JComboBox box) {
		this.choice = box;
		return;
	}
	
	public void setJTextArea(JTextArea area) {
		this.textShow = area;
		return;
	}
	
	@Override
	public void itemStateChanged(ItemEvent arg0) {
		// TODO Auto-generated method stub
		this.textShow.setText(null);
		String fileName = this.choice.getSelectedItem().toString();
		try (BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));){
			String s = null;
			while ((s = in.readLine()) != null) {
				this.textShow.append(s+'\n');
			}
		}catch(Exception e) {
			this.textShow.append(e.toString());
		}
	}
}
